// by Xeno
#define THIS_FILE "x_missionssetup.sqf"
#include "x_setup.sqf"

// I'm using x_mXX.sqf for the mission filename where XX (index number) has to be added to GVAR(sm_array)
GVAR(sm_fname) = "x_m";

// GVAR(sm_array) contains the indices of the sidemissions (it gets shuffled later)
// to remove a specific side mission just remove the index from GVAR(sm_array)

// TYRGHEN - The structure of the sm_array building is fully changed
GVAR(sm_array) = switch(tolower(worldName)) do {
  case "stratis": {[0,1,3,4,6,8,9,11,12,14,19,20,23,29,31,32,36,40,42,44,51,52]};
  // 150 - artillery
  // 129 - destroy tanks
  // 137 - prisoners
  // 146 - destroy industrial buildings
  case "altis": {[515,516,517,518,519,520,521,522,523,524,525,526,527,528,106,150,129,137,146,100,101,102,103,104,105,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,131,132,133,134,135,136,138,139,140,141,142,143,144,145,147,148,149,151,152,153,154,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,529]};
  default { [] };
};

// TYRGHEN - Remove time based missions
if (GVAR(FastTime) > 0) then {GVAR(sm_array) = GVAR(sm_array) - [151,152]};

#ifdef __TT__
// TYRGHEN - remove missions containing enemy officers or the SCUD, because the officer/scud type is different depending on the side
GVAR(sm_array) = switch(tolower(worldName)) do {
  case "stratis": {GVAR(sm_array) - [7,11,107,111]};
  case "altis": {GVAR(sm_array) - [7,107]};
  default { GVAR(sm_array) };
};
#endif

if (GVAR(FastTime) > 0) then {
	GVAR(sm_array) = switch(tolower(worldName)) do {
	  case "stratis": {GVAR(sm_array)};
	  case "altis": {GVAR(sm_array)};
	  default {GVAR(sm_array)};
	};
};

GVAR(number_side_missions) = count GVAR(sm_array);
__TRACE_1(QGVAR(number_side_missions),QGVAR(number_side_missions))

// just for debugging
// it will create markers at each sidemission position
#ifdef __SMMISSIONS_MARKER__
0 spawn {
	sleep 1;
	{
		_ffolder = "ma3";
		_mfolder = "x_missions\" + _ffolder + "\%2%1.sqf";
		[1,1] call compile preprocessFileLineNumbers (format [_mfolder, _x, GVAR(sm_fname)]);
		_start_pos = GVAR(x_sm_pos) select 0;
		_name = format [(localize "STR_DOM_MISSIONSTRING_711"), _x];
		_marker= createMarkerLocal [_name, _start_pos];
		_marker setMarkerTypeLocal "hd_dot";
		_name setMarkerColorLocal "ColorBlack";
		_name setMarkerSizeLocal [0.2,0.2];
		_name setMarkerTextLocal _name;
		diag_log [_name, GVAR(x_sm_pos)];
	} forEach GVAR(sm_array);
};
#endif

if (call FUNC(checkSHC)) then {		
	// these vehicles get spawned in a convoy sidemission. Be aware that it is the best to use a wheeled vehicle first as leader.
	// at least wheeled AI vehicles try to stay on the road somehow
	GVAR(sm_convoy_vehicles) = switch (GVAR(enemy_side)) do {
		case "OPFOR": {["O_MRAP_02_gmg_F","O_APC_Wheeled_02_rcws_F", "O_APC_Tracked_02_cannon_F", "O_Truck_02_covered_F", "O_Truck_02_covered_F", "O_Truck_02_transport_F", "O_MRAP_02_hmg_F"]};
		case "BLUFOR": {["B_MRAP_01_gmg_F","B_APC_Tracked_01_rcws_F", "B_MBT_01_cannon_F", "B_Truck_01_Repair_F", "B_Truck_01_fuel_F", "B_Truck_01_ammo_F", "B_APC_Tracked_01_AA_F"]};
		case "INDEPENDENT": {["BTR40_MG_TK_GUE_EP1","BRDM2_TK_GUE_EP1", "Ural_ZU23_TK_GUE_EP1", "V3S_Repair_TK_GUE_EP1", "V3S_Refuel_TK_GUE_EP1", "V3S_Reammo_TK_GUE_EP1", "T55_TK_GUE_EP1"]};
	};
	
	GVAR(smb2_protect_convoy_vehicles) = ["B_APC_Wheeled_01_cannon_F","B_APC_Wheeled_01_cannon_F","B_APC_Wheeled_01_cannon_F","B_APC_Wheeled_01_cannon_F","B_APC_Wheeled_01_cannon_F"];
	GVAR(smb1_protect_convoy_vehicles) = ["B_MRAP_01_gmg_F","B_Truck_01_covered_F","B_Truck_01_covered_F","B_Truck_01_covered_F","B_MRAP_01_gmg_F"];
	GVAR(smb_protect_convoy_vehicles) = ["B_APC_Wheeled_01_cannon_F","B_MRAP_01_gmg_F","B_Truck_01_covered_F","B_Truck_01_transport_F","B_Truck_01_covered_F","B_MRAP_01_gmg_F"];
	GVAR(smi_ammo_convoy_vehicles) = ["I_MRAP_03_gmg_F","I_Truck_02_ammo_F","I_MRAP_03_gmg_F","I_Truck_02_ammo_F","I_Truck_02_ammo_F","I_Truck_02_ammo_F","I_Truck_02_fuel_F","I_MRAP_03_gmg_F","I_MRAP_03_gmg_F"];
	GVAR(smo_ammo_convoy_vehicles) = ["O_APC_Wheeled_02_rcws_F","O_Truck_02_fuel_F","O_Truck_02_ammo_F","O_Truck_02_ammo_F","O_MRAP_02_gmg_F","O_Truck_02_ammo_F","O_Truck_02_transport_F","O_APC_Wheeled_02_rcws_F"];
	GVAR(smb_ammo_convoy_vehicles) = ["B_APC_Wheeled_01_cannon_F","B_MRAP_01_gmg_F","B_Truck_01_transport_F","B_Truck_01_transport_F","B_Truck_01_transport_F","B_Truck_01_transport_F","B_Truck_01_transport_F","B_MRAP_01_gmg_F"];
	GVAR(smi_troop_convoy_vehicles) = ["I_MRAP_03_gmg_F","I_MRAP_03_hmg_F","I_Truck_02_covered_F","I_Truck_02_fuel_F","I_Truck_02_covered_F","I_Truck_02_covered_F","I_MRAP_03_hmg_F","I_MRAP_03_gmg_F"];
	GVAR(smo_troop_convoy_vehicles) = ["O_APC_Wheeled_02_rcws_F","O_Truck_02_covered_F","O_Truck_02_covered_F","O_MRAP_02_gmg_F","O_Truck_02_covered_F","O_Truck_02_covered_F","O_APC_Wheeled_02_rcws_F"];
	GVAR(smb_troop_convoy_vehicles) = ["B_MRAP_01_gmg_F","B_Truck_01_covered_F","B_Truck_01_covered_F","B_MRAP_03_hmg_F","BTruck_01_covered_F","B_Truck_01_covered_F","B_Truck_01_covered_F","B_MRAP_01_gmg_F"];

	GVAR(sm_pickups) = switch (GVAR(enemy_side)) do {
	    case "OPFOR": {["C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F"]};
	    case "BLUFOR": {["C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F"]};
	    case "INDEPENDENT": {["C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F","C_Offroad_01_F"]};
	};
	GVAR(sm_speedboat_convoy) = switch (GVAR(enemy_side)) do {
		case "OPFOR": {["O_Boat_Armed_01_hmg_F","O_Boat_Transport_01_F","O_Boat_Transport_01_F","O_Boat_Armed_01_hmg_F","O_Boat_Transport_01_F","O_Boat_Armed_01_hmg_F"]};
		case "BLUFOR": {["B_Boat_Armed_01_minigun_F","B_Boat_Transport_01_F","B_Boat_Transport_01_F","B_Boat_Armed_01_minigun_F","B_Boat_Transport_01_F","B_Boat_Transport_01_F","B_Boat_Armed_01_minigun_F"]};
		case "INDEPENDENT": {["I_Boat_Armed_01_hmg_F","I_Boat_Transport_01_F","I_Boat_Armed_01_hmg_F","I_Boat_Transport_01_F","I_Boat_Armed_01_hmg_F"]};
	};
	GVAR(sm_armour_convoy_vehicles) = switch (GVAR(enemy_side)) do {
		case "OPFOR": {["O_APC_Wheeled_02_rcws_F","O_Truck_02_ammo_F","O_APC_Wheeled_02_rcws_F","O_Truck_02_fuel_F","O_APC_Wheeled_02_rcws_F","O_APC_Wheeled_02_rcws_F","O_APC_Wheeled_02_rcws_F"]};
		case "BLUFOR": {["M1126_ICV_M2_EP1","M2A3_EP1", "M6_EP1", GVAR(rep_truck_blufor), "MtvrRefuel_DES_EP1", "MtvrReammo_DES_EP1", "M1A2_US_TUSK_MG_EP1"]};
		case "INDEPENDENT": {["I_MRAP_03_gmg_F","I_MRAP_03_gmg_F","I_MRAP_03_gmg_F","I_MRAP_03_gmg_F","I_MRAP_03_gmg_F","I_MRAP_03_gmg_F","I_MRAP_03_hmg_F"]};
	};
};

// Instead of a random vehicle chosen for winning a side mission you can setup it in the mission yourself now
// Add GVAR(current_sm_bonus_vec) to the beginning of a sidemission script with a vehicle class string and that vehicle gets chosen instead of a random one.
// Examples:
// GVAR(current_sm_bonus_vec) = "M1A1_US_DES_EP1";
// TT (first blufor then opfor):
// GVAR(current_sm_bonus_vec) = ["M1A1_US_DES_EP1", "T72_TK_EP1"];
// DON'T CHANGE IT HERE IN X_MISSIONSETUP.SQF!!!!!!!!!!!!!!!!!!!!!!!!!
if (call FUNC(checkSHC)) then {
	#ifndef __TT__
	GVAR(current_sm_bonus_vec) = "";
	#else
	GVAR(current_sm_bonus_vec) = ["",""];
	#endif
};
